package com.yiwei.zxp.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.yiwei.zxp.R;
import com.yiwei.zxp.api.model.GoodsHistoryDayModel;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class TimeSelectAdapter extends ItemAdapter<GoodsHistoryDayModel.DatasBean, TimeSelectAdapter.DefaultHolder> {


    private int selectPoi = -1;

    public TimeSelectAdapter(Context context) {
        super(context);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_time_select, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        GoodsHistoryDayModel.DatasBean item = getItem(position);
        holder.txtTime.setText(item.name);
        if (selectPoi == position) {
            holder.imgCheck.setImageResource(R.mipmap.img_check_box_check);
        } else {
            holder.imgCheck.setImageResource(R.mipmap.img_check_box_uncheck);
        }
        holder.layoutTotal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectPoi = position;
                notifyDataSetChanged();
            }
        });
    }

    public int getSelectPoi() {
        return selectPoi;
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_time)
        TextView txtTime;
        @BindView(R.id.img_check)
        ImageView imgCheck;
        @BindView(R.id.layout_total)
        FrameLayout layoutTotal;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
